﻿/*----------------------------------------------------------------
//Copyright (C) 2012 赵国伟
//文件功能描述：后台登录脚本
//创建人：赵国伟
//生成时间：2012/03/17 16:15:00
//----------------------------------------------------------------*/


///刷新验证码；
function ChangeVerifyCode() {
    $("#spImgCode").html("<img src='/Public/VerifyCode.aspx?tt=" + Math.random() + "'  width='54' height='25' align='absbottom' />");
}


function Login() {
    $("#btnLogin").attr("disabled", true);
    var userName = $("#txtUserName").val();
    var pwd = $("#txtPwd").val();
    var code = $("#txtCode").val();
    if (userName == "") {
        alert("系统提示：请输入用户名！");
        $("#txtUserName").focus();
        $("#btnLogin").attr("disabled", false);
        return;
    }
    if (pwd == "") {
        alert("系统提示：请输入登录密码！");
        $("#txtPwd").focus();
        $("#btnLogin").attr("disabled", false);
        return;
    }
    if (code == "") {
        alert("系统提示：请输入验证码！");
        $("#txtCode").focus();
        $("#btnLogin").attr("disabled", false);
        return;
    }

    var url = "/Manage/AS/LoginCommon.aspx?Action=Login";
    url += "&tttt=" + Math.random();
    var data = "UserName=" + encodeURI(userName);
    data += "&PassWord=" + pwd;
    data += "&Code=" + code;
    $.ajax(
    {
        type: "POST",
        url: url,
        data: data,
        dataType: "json",
        success: function (ret) {
            if (ret.Result == 1) {
                if ($("#hfBackUrl").val() == "")
                    location.href = "/Manage/Default.aspx";
                else
                    location.href = $("#hfBackUrl").val();
            }
            else {
                alert(ret.Message);
                ChangeVerifyCode();
                $("#txtCode").val("");
                $("#btnLogin").attr("disabled", false);
            }
        }
    });
}


//为每个页面注册一个事件；
document.onkeydown = function (e) {
    var e = window.event ? window.event : e;
    var a = e.srcElement || e.target;
    if (e.keyCode == 13 && a.type != "textarea") {
        $("#btnLogin").click();
        e.cancelBubble = true;
        e.returnValue = false;
    }
}

